package interactor;

import byggeTegner.DrawPanel;
import context.*;


import geometry2D.MetricPoint2D;

import java.awt.Graphics2D;

import object2D.TextObject;

import org.json.JSONException;


// ********************************************************************
// *** CLASS: DrawTextInteractor
// ********************************************************************
public class DrawTextInteractor extends Interactor implements Context.Constants
{ //private static final boolean DEBUG=true; // Overriding Context.Constants.DEBUG
  static final String TAG="interactor.DrawTextInteractor";

  public String getMouseModeMnemonic() { return("Draw Text"); }
  private TextObject text; // !null when drawing

  // ******************************************************************
  // *** CONSTRUCTOR: DrawTextInteractor
  // ******************************************************************
  public DrawTextInteractor(DrawPanel drawPanel)
  { super(drawPanel,DRAW_TEXT); }

  // ******************************************************************
  // *** METHOD: paintMouseEffect
  // ******************************************************************
  public void paintMouseEffect(Graphics2D g)
  { if(text!=null) text.paint(g,drawPanel); }

  // ******************************************************************
  // *** METHOD: mouseDragged
  // ******************************************************************
  // Invoked when a mouse button is pressed and then dragged.
  protected void mouseDragged() {}

  // ******************************************************************
  // *** METHOD: mouseMoved
  // ******************************************************************
  // Invoked when the mouse has been moved (with no buttons down).
  protected void mouseMoved() {}

  // ******************************************************************
  // *** METHOD: mousePressed
  // ******************************************************************
  // Invoked when a mouse button has been pressed.
  protected void mouseLeftPressed(MetricPoint2D p)
  { if(text==null)
	{ try { text=new TextObject(drawPanel.getObjectModel(),p); }
	  catch(JSONException e) { e.printStackTrace(); }
	  drawPanel.repaint();
	}
  }
  protected void mouseRightPressed(MetricPoint2D p) {}

  // ******************************************************************
  // *** METHOD: mouseReleased
  // ******************************************************************
  // Invoked when a mouse button has been released.
  protected void mouseLeftReleased(MetricPoint2D p)
  { drawObjectDone(text,"TEXT");  
    text=null; drawPanel.repaint();
  }
  protected void mouseRightReleased(MetricPoint2D p) {}

}